import 'package:flutter/material.dart';
import 'package:yp/config/style.dart';
import 'package:yp/widgets/dashed_line.dart';
import 'package:yp/widgets/line.dart';

/// 排行榜
class RankingList extends StatefulWidget {
  const RankingList({Key key}) : super(key: key);

  @override
  _RankingListState createState() => _RankingListState();
}

class _RankingListState extends State<RankingList>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return CustomScrollView(slivers: [
      SliverToBoxAdapter(
          child: Column(
        children: [
          Row(
            children: [
              Expanded(
                flex: 2,
                child: Padding(
                  padding: const EdgeInsets.only(top: 10, bottom: 14),
                  child: Center(
                    child: Text('排行',
                        style: TextStyle(
                            color: EsColors.Title,
                            fontSize: EsSizes.SM,
                            fontWeight: EsFontWeights.Medium)),
                  ),
                ),
              ),
              Expanded(
                flex: 2,
                child: Padding(
                  padding: const EdgeInsets.only(top: 10, bottom: 14),
                  child: Center(
                    child: Text('头像',
                        style: TextStyle(
                            color: EsColors.Title,
                            fontSize: EsSizes.SM,
                            fontWeight: EsFontWeights.Medium)),
                  ),
                ),
              ),
              Expanded(
                flex: 2,
                child: Padding(
                  padding: const EdgeInsets.only(top: 10, bottom: 14),
                  child: Center(
                    child: Text('昵称',
                        style: TextStyle(
                            color: EsColors.Title,
                            fontSize: EsSizes.SM,
                            fontWeight: EsFontWeights.Medium)),
                  ),
                ),
              ),
              Expanded(
                flex: 3,
                child: Align(
                  alignment: Alignment.centerRight,
                  child: Text('助力值',
                      style: TextStyle(
                          color: EsColors.Title,
                          fontSize: EsSizes.SM,
                          fontWeight: EsFontWeights.Medium)),
                ),
              ),
              SizedBox(width: 27)
            ],
          ),
          YpLine(indent: 12),
          Container(
            child: ListView.separated(
                shrinkWrap: true,
                physics: NeverScrollableScrollPhysics(),
                padding: EdgeInsets.zero,
                itemBuilder: (context, index) => _item(index),
                separatorBuilder: (context, index) => Padding(
                      padding: const EdgeInsets.only(left: 12),
                      child: DashLine(
                          color: Color(0xffd8d8d8), height: 1, dashWidth: 6),
                    ),
                itemCount: 10),
          ),
          YpLine(indent: 12),
          SizedBox(height: 14),
          Center(
              child: Text('到底了~',
                  style: TextStyle(
                      color: EsColors.ContentSecondary,
                      fontSize: EsSizes.XXS,
                      fontWeight: EsFontWeights.Normal))),
          SizedBox(height: 20),
        ],
      ))
    ]);
  }

  Widget _item(int index) {
    return Padding(
      padding: const EdgeInsets.only(top: 10, bottom: 12),
      child: Row(
        children: [
          Expanded(
            flex: 2,
            child: Center(
              child: Text((index + 1).toString(),
                  style: TextStyle(
                      color: _getItemColor(index),
                      fontSize: EsSizes.SM,
                      fontWeight: EsFontWeights.Medium)),
            ),
          ),
          Expanded(
            flex: 2,
            child: Center(
              child: Image(
                  image: AssetImage("assets/images/level.png"), width: 25.0),
            ),
          ),
          Expanded(
            flex: 2,
            child: Center(
              child: Text('张三',
                  style: TextStyle(
                      color: EsColors.TitleSecondary,
                      fontSize: EsSizes.SM,
                      fontWeight: EsFontWeights.Normal)),
            ),
          ),
          Expanded(
            flex: 3,
            child: Align(
              alignment: Alignment.centerRight,
              child: Text('999',
                  style: TextStyle(
                      color: Color(0xffc61a24),
                      fontSize: EsSizes.SM,
                      fontWeight: EsFontWeights.Medium)),
            ),
          ),
          SizedBox(width: 27)
        ],
      ),
    );
  }

  Color _getItemColor(int index) {
    switch (index) {
      case 0:
        return Color(0xffee323d);
        break;
      case 1:
        return Color(0xfff5a623);
        break;
      case 2:
        return Color(0xff9dadd1);

        break;
      default:
        return EsColors.ContentSecondary;
    }
  }
}
